<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm"   ref="dataForm"  :rules="dataRule"  @keyup.enter.native="dataFormSubmit()"  label-width="80px">
      <el-form-item label="职称名称" prop="professionalTitle">
        <el-input v-model="dataForm.professionalTitle	" placeholder="职称名称"></el-input>
      </el-form-item>
      <el-form-item label="排序" prop="sort" style="margin-top: 50px">
        <el-input type="number" v-model="dataForm.sort" placeholder="排序"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button  @click="visible = false">取消</el-button>
      <el-button  type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    name: 'notice-add',
    data () {
      return {
        visible: false,
        dataForm: {
          professionalTitle: '',
          sort: ''
        },
        dataRule: {
          professionalTitle: [
            {required: true, message: '职称不能为空', trigger: 'blur'}
          ],
          sort: [
            {required: true, message: '排序不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.dataForm = {}
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/user/professionaltitle/info/${this.dataForm.id}`),
            method: 'post'
          }).then(data => {
            if (data && data.code === 200) {
              // this.dataForm.level = data.data.educationLevel.level
              // this.dataForm.sort = data.data.educationLevel.sort
            }
          })
        }
      },
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/user/professionaltitle/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: {
                'professionalTitle': this.dataForm.professionalTitle,
                'sort': this.dataForm.sort
              }
            }).then(data => {
              if (data && data.code === 200) {
                this.$message({
                  'message': '操作成功',
                  'type': 'success',
                  'duration': 1500
                })
                this.visible = false
                this.$emit('refreshDataList')
                // this.dataForm = {}
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
